//
// Created by Administrator on 2023/7/28.
//
#include <vector>
#include <string>
#include <iostream>
#include <unordered_map>

using namespace std;

class Solution {
public:
    int similarPairs(vector<string> &words) {
        // 每个word都列出构成字母
        vector<string> elements(words.size(), string(26, '0'));
        for (int i = 0; i < words.size(); ++i) {
            for (int j = 0; j < words[i].size(); ++j) {
                elements[i][words[i][j] - 'a'] = '1';
            }
        }
        int count = 0;
        for (int i = 0; i < elements.size(); ++i) {
            for (int j = i + 1; j < elements.size(); ++j) {
                if (elements[i] == elements[j])
                    ++count;
            }
        }
        return count;
    }
};
class Solution2 {
public:
    int similarPairs(vector<string>& words) {
        unordered_map<int, int> mp;
        int n = words.size(), ans = 0;
        for (auto& word : words) {
            int bit = 0;
            for (auto& ch : word) bit |= (1 << (ch - 'a'));
            ans += mp[bit]++;
        }
        return ans;
    }
};


int main() {
    vector<string> words{"aba", "aabb", "abcd", "bac", "aabc", "zycdweadasgfeg"};
    Solution2 s;
    cout << s.similarPairs(words) << endl;
}